# 设置最低版本要求
cmake_minimum_required(VERSION 3.10)

# 项目名称和语言
project(Question_Final LANGUAGES CXX)

add_subdirectory(lib/cmsh)
# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# 指定包含路径
include_directories(include)
include_directories(lib/cmsh/include)

find_package(OpenMP REQUIRED)

# 源文件列表
set(SRC_FILES
    src/main.cpp
    src/func.cpp
)

link_directories(${CMAKE_BINARY_DIR}/lib/cmsh/)

# 生成可执行文件
add_executable(GridConvert ${SRC_FILES})
target_link_libraries(GridConvert PRIVATE OpenMP::OpenMP_CXX shared)
add_dependencies(GridConvert shared)

set_target_properties(GridConvert PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set_target_properties(shared PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

# 编译选项
if(MSVC)
    # 使用 MSVC 编译器
    target_compile_options(GridConvert PRIVATE
        $<$<CONFIG:Debug>:/Od /RTC1>                     # Debug 配置：禁用优化，启用运行时检查
        $<$<CONFIG:Release>:/O2 /fp:fast /MD>            # Release 配置：优化代码，启用快速浮点模型
    )
else()
    # 使用 GCC 或 Clang 编译器
    target_compile_options(GridConvert PRIVATE
        $<$<CONFIG:Debug>:-O1 -g>                        # Debug 配置：禁用优化，启用调试信息
        $<$<CONFIG:Release>:-O2>                      # Release 配置：最大化优化
    )
endif()